package com.newear.happyDialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.newear.R;
import com.newear.util.Validator;

/**
 * Created by happy on 2018/5/27.
 */

public class WifiPasswordDialog extends AlertDialog {
    private Context mContext;
    private TextView mTextView;
    private EditText et_wifi_password;
    private Button mSureBUtton;
    private String mWifiTitle;

    public WifiPasswordDialog(Context context, int themeResId, String title) {
        super(context, themeResId);
        mContext = context;
        mWifiTitle = title;
        //点击外面不允许消失,包括返回键
        setCanceledOnTouchOutside(false);
        getWindow().getAttributes().gravity = Gravity.CENTER;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wifi_password_dialog);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        mTextView = (TextView) findViewById(R.id.tv_password_wifi_name);
        et_wifi_password = (EditText) findViewById(R.id.et_wifi_password);
        mSureBUtton =  (Button) findViewById(R.id.btn_wifi_sure);
        mSureBUtton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null){
                    String pwd = et_wifi_password.getText().toString().trim();
                    if (Validator.isEffective(pwd)) {
                        listener.sureClickListener(pwd);
                    } else {
                        Toast.makeText(mContext, "请先输入密码！", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        mTextView.setText(mWifiTitle);
    }


    OnSureClickListener listener;

    public interface OnSureClickListener{
        void sureClickListener(String passwWord);
    }

    public void setOnSureClickListener(OnSureClickListener listener){
        this.listener = listener;
    }



}
